import 'package:flutter/material.dart';

/// @Author wywinstonwy
/// @Date 2022/10/19 09:14
/// @Description: 

class SwipeLeftReturnWidget extends StatelessWidget {
  final Widget child;
  bool _isOverscroll = false;
  SwipeLeftReturnWidget(this.child);


  @override
  Widget build(BuildContext context) {
    return NotificationListener<ScrollNotification>(
        child: child,
        onNotification: (notification){
          print(notification.runtimeType);

          switch(notification.runtimeType){

            case ScrollUpdateNotification:
              _isOverscroll = false;
              break;
            case ScrollEndNotification:
              if(_isOverscroll){
                //返回上一页
                Navigator.of(context).pop();
              }
              break;
            case OverscrollNotification:
              if(notification.depth == 0 && notification.metrics.extentBefore <= 0){
                //处于第一个tab并且继续左滑
                _isOverscroll = true;
              }
              break;
            default:
              break;
          }
          return false;
        },
    );
  }
}

